<template>
    <div class="common-box" v-if="boxIsShow">
        <div class="common-content-box">
            <div class="content-table-box">
                <div class="content_table_title_box">
                    <img src="@/assets/icon-data.png" class="content_table_title_icon">
                    <div class="content_table_title">租户列表</div>
                </div>
                <div class="table_search_box">
                    <el-form :inline="true" :model="searchForm" class="demo-form-inline" style="display: inline-block;">
                        <el-form-item label="租户名称" style="margin-bottom: 0;">
                            <el-input v-model="searchForm.name" placeholder="请输入租户名称" size="small"></el-input>
                        </el-form-item>
                        <el-form-item style="margin-bottom: 0;">
                            <el-button type="primary" @click="onSubmit" size="small">查询</el-button>
                        </el-form-item>
                    </el-form>
                    <el-button type="primary" @click="toAdd" style="float: right;margin-right: 2%;">新建租户</el-button>
                </div>
                <div class="table_box">
                    <el-table
                        :data="tableData"
                        style="width: 100%;"
                        height="92%">
                        <el-table-column
                        fixed
                        prop="supplierName"
                        label="租户名称"
                        width="180">
                        </el-table-column>
                        <el-table-column
                        prop="supplierLxr"
                        label="联系人"
                        width="150">
                        </el-table-column>
                        <el-table-column
                        prop="supplierPhone"
                        label="联系电话"
                        width="180">
                        </el-table-column>
                        <el-table-column
                        prop="supplierPwd"
                        label="密码"
                        width="180">
                        </el-table-column>
                        <el-table-column
                        prop="supplierAddress"
                        label="地址"
                        width="300">
                        </el-table-column>
                        <el-table-column
                        prop="createTime"
                        label="创建时间"
                        width="180">
                        </el-table-column>
                        <el-table-column
                        label="操作"
                        width="200">
                        <template slot-scope="scope">
                            <el-button @click="toEdit(scope.row)" type="text" size="medium">编辑</el-button>
                            <el-button @click="toWuliu(scope.row)" type="text" size="medium">物流配置</el-button>
                        </template>
                        </el-table-column>
                    </el-table>
                    <pagination
                    :total="total"
                    :limit="pageSize"
                    :page="pageNumber"
                    :pageSize="pageSize"
                    @pageChange="pageChange"
                    ></pagination>
                </div>
            </div>
        </div>
        <add-supplierBox 
        ref="addSupplierBox"
        @close="
          getData();
        "
      ></add-supplierBox>
      <add-supplierWuliu
      ref="addSupplierWuliu"
        @close="
          getData();
        "
      ></add-supplierWuliu>
    </div>
</template>
<script>
import Pagination from "@/components/pagination.vue";
import addSupplierBox from "@/components/addSupplierBox.vue";
import addSupplierWuliu from "@/components/addSupplierWuliu.vue";
export default {
  components: {
    Pagination,
    addSupplierBox,
    addSupplierWuliu
  },
  data() {
    return {
        total: 0,
        pageSize: 30,
        pageNumber: 1,
        tableData: [],
        boxIsShow:false,
        searchForm:{
          name:''
        },
        tableData: []
    };
  },
  created() {
    
  },
  mounted(){
    
  },
  methods: {
    __init() {
      this.getData();
    },
    getData(){
      var url="manager/getSuppliersByPage";
      var params={
        pageSize: this.pageSize,
        pageNum: this.pageNumber,
        name:this.searchForm.name
      }
      this.$post(url, params).then((res) => {
        console.log(res)
        if (res.code === 0) {
          this.total = res.data.total;
          this.tableData=res.data.list;
        } else {
          this.$message.error(res.msg)
        }
      });
    },
    pageChange(e) {
      console.log(e)
      this.pageNumber = e.page;
      this.getData();
    },
    onSubmit(){
      this.pageNumber=1;
      this.getData();
    },
    toAdd(){
      if (this.$refs.addSupplierBox) {
        // 显示当前详情
        this.$refs.addSupplierBox.tkIsShow = true;
        this.$refs.addSupplierBox.title = "新增租户";
        this.$refs.addSupplierBox.__init("add");
      }
    },
    toEdit(item){
      if (this.$refs.addSupplierBox) {
        // 显示当前详情
        this.$refs.addSupplierBox.tkIsShow = true;
        this.$refs.addSupplierBox.title = "编辑租户";
        this.$refs.addSupplierBox.__init("edit",item);
      }
    },
    toWuliu(item){
      if (this.$refs.addSupplierWuliu) {
        // 显示当前详情
        this.$refs.addSupplierWuliu.tkIsShow = true;
        this.$refs.addSupplierWuliu.title = "编辑物流信息";
        this.$refs.addSupplierWuliu.__init("edit",item);
      }
    }
  }
}
</script>
<style scoped lang="scss">
  .common-box{
    background-color: #f9f9fb;
    height: 100%;
  }
  .common-content-box{
    height: 95%;
    margin-top: 2%;
    width: 96%;
    display: inline-block;
  }
  .content-table-box{
    background-color: #fff;
    width: 100%;
    height: 100%;
    border-radius: 5px;
    box-shadow: 0 0 5px 1px rgba(83, 83, 83, 0.1);
  }
  .content_table_title_box{
    position: relative;
    height: 30px;
    margin-top: 10px;
    width: 100%;
    display: inline-block;
  }
  .content_table_title_icon{
    position: absolute;
    left: 15px;
    height: 18px;
    top: 6px;
  }
  .content_table_title{
    position: absolute;
    line-height: 34px;
    height: 100%;
    font-size: 15px;
    color: #42484e;
    left: 40px;
  }
  .table_search_box{
    text-align: left;
    margin-top: 10px;
    margin-left: 2%;
  }
  .table_box{
    height: calc(100% - 100px);
    margin-top: 10px;
    width: 96%;
    margin-left: 2%;
  }
  ::v-deep .el-form--inline .el-form-item__content{
    width: 140px;
  }
  ::v-deep .el-select>.el-input{
    width: 120px;
  }
</style>